
import { GCtrl } from "../../lib/util/GCtrl";
import DWC_ChangeHead from "./DWC_ChangeHead";

const { ccclass, property } = cc._decorator;

@ccclass
export default class headItem extends cc.Component {

    @property(cc.Sprite)
    head: cc.Sprite = null;

    // LIFE-CYCLE CALLBACKS:
    private myInfo = GCtrl.session.getPlayer();
    private pChangeHead: DWC_ChangeHead = null;
    private pickEventName: string = null;
    private headId: string = null;
    private itemIdx: number = null;
    /** 初始化头像item */
    init(args: any) {
        this.pChangeHead = args.pChangeHead;
        this.pickEventName = args.pickEventName;
        this.headId = args.id;
        this.itemIdx = args.idx;
        let selfHeadId = this.myInfo.logo;
        GCtrl.setHeadSpr(this.headId, this.head);
        this.headId == selfHeadId && this.onClickHead();
    }
    /** 点击头像 */
    onClickHead() {
        this.pChangeHead.node.emit(this.pickEventName, {
            head: this.node,
            headId: this.headId,
            itemIdx: this.itemIdx
        });
    }
}
